<!DOCTYPE HTML>
<script src="../../../resources/js-test.js"></script>
<script src="resources/elementsFromPoint.js"></script>
<style>
html, body {
    margin: 0;
    padding: 0;
}
body {
    height: 500px;
}
#iframe {
    width: 200px;
    height: 200px;
}
#iframeScrollbars {
    position: absolute;
    top: 0;
    left: 0;
    transform: translate(50px, 50px);
    width: 150px;
    height: 150px;
    overflow-y: scroll;
    overflow-x: scroll;
}
</style>
<iframe id="iframe" srcdoc="<div id='div' style='width: 100px; height: 100px; background: red'></div>"></iframe>
<iframe id="iframeScrollbars" srcdoc="<div id='big' style='width: 500px; height: 500px; background: blue;'></div><div id='div' style='position: absolute; top: 0; left: 0; width: 100px; height: 100px; background: green;'>"></iframe>
<div id="console"></div>
<script>
window.jsTestIsAsync = true;

if (window.testRunner)
    testRunner.dumpAsText();

onload = function() {
    checkElementsFromPointFourCorners('document', 'iframe');
    checkElementsFromPointFourCorners('document.getElementById(\'iframe\').contentDocument', 'document.getElementById(\'iframe\').contentDocument.getElementById(\'div\')');
    checkElementsFromPointFourCorners('document', 'iframeScrollbars');
    checkElementsFromPointFourCorners('document.getElementById(\'iframeScrollbars\').contentDocument', 'document.getElementById(\'iframeScrollbars\').contentDocument.getElementById(\'div\')');

    // Ensure that elements outside the inner document's viewport are not returned.
    shouldBeEqualToNumber('document.getElementById(\'iframeScrollbars\').contentDocument.elementsFromPoint(-1, -1).length', 0);
    shouldBeEqualToNumber('document.getElementById(\'iframeScrollbars\').contentDocument.elementsFromPoint(1, 1).length', 2);
    shouldBeEqualToNumber('document.getElementById(\'iframeScrollbars\').contentDocument.elementsFromPoint(500, 500).length', 0);
    shouldBeEqualToNumber('document.getElementById(\'iframeScrollbars\').contentDocument.elementsFromPoint(140, 140).length', 0);

    finishJSTest();
}
</script>
